package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.domain.ZhGameInfo;
import com.ruoyi.system.service.IZhGameInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ZhDeptGame;
import com.ruoyi.system.service.IZhDeptGameService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.service.IZhDeptInfoService;
import com.ruoyi.common.domain.ZhDeptInfo;

/**
 * 站点游戏 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-06-23
 */
@Controller
@RequestMapping("/system/zhDeptGame")
public class ZhDeptGameController extends BaseController
{
    private String prefix = "system/zhDeptGame";

	@Autowired
	private IZhDeptGameService zhDeptGameService;

	@Autowired
	private IZhDeptInfoService zhDeptInfoService;

	@Autowired
	private IZhGameInfoService zhGameInfoService;


	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhDeptGame:view")
	@GetMapping()
	public String zhDeptGame(ZhDeptGame zhDeptGame,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhDeptGame.getParams())));
		mmap.put("zhGameInfos" , zhGameInfoService.selectZhGameInfoList(buildParamsContainer(ZhGameInfo.class,null)));
		return prefix + "/zhDeptGame";
	}
	
	/**
	 * 查询站点游戏列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhDeptGame:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ZhDeptGame zhDeptGame)
	{
		startPage();
        List<ZhDeptGame> list = zhDeptGameService.selectZhDeptGameList(zhDeptGame);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出站点游戏列表
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhDeptGame:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhDeptGame zhDeptGame)
    {
    	List<ZhDeptGame> list = zhDeptGameService.selectZhDeptGameList(zhDeptGame);
        ExcelUtil<ZhDeptGame> util = new ExcelUtil<ZhDeptGame>(ZhDeptGame.class);
        return util.exportExcel(list, "zhDeptGame");
    }
	
	/**
	 * 新增站点游戏
	 */
	@RequiresPermissions("system:zhDeptGame:add")
	@DataScope(tableAlias = "l")
	@GetMapping("/add")
	public String add(ZhDeptGame zhDeptGame,ModelMap mmap)
	{
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhDeptGame.getParams())));
		mmap.put("zhGameInfos" , zhGameInfoService.selectZhGameInfoList(new ZhGameInfo()));

		return prefix + "/add";
	}
	
	/**
	 * 新增保存站点游戏
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhDeptGame:add")
	@Log(title = "站点游戏", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ZhDeptGame zhDeptGame)
	{		
		return toAjax(zhDeptGameService.insertZhDeptGame(zhDeptGame));
	}

	/**
	 * 修改站点游戏
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhDeptGame:edit")
	@GetMapping("/edit/{id}")
	public String edit(ZhDeptGame zhDeptGame,@PathVariable("id") Integer id, ModelMap mmap)
	{
		ZhDeptGame result = zhDeptGameService.selectZhDeptGameById(id);
		mmap.put("zhDeptGame", result);
		mmap.put("zhDepts" , zhDeptInfoService.selectZhDeptInfoList(buildParamsContainer(ZhDeptInfo.class,zhDeptGame.getParams())));
		mmap.put("zhGameInfos" , zhGameInfoService.selectZhGameInfoList(buildParamsContainer(ZhGameInfo.class,zhDeptGame.getParams())));
		return prefix + "/edit";
	}
	
	/**
	 * 修改保存站点游戏
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhDeptGame:edit")
	@Log(title = "站点游戏", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ZhDeptGame zhDeptGame)
	{		
		return toAjax(zhDeptGameService.updateZhDeptGame(zhDeptGame));
	}
	
	/**
	 * 删除站点游戏
	 */
	@DataScope(tableAlias = "l")
	@RequiresPermissions("system:zhDeptGame:remove")
	@Log(title = "站点游戏", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(ZhDeptGame zhDeptGame,String ids)
	{		
		return toAjax(zhDeptGameService.deleteZhDeptGameByIds(ids));
	}
	
}
